package com;

import tool.jdbctool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@WebServlet(name = "ques_delete")
public class ques_delete extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();
        Connection connection=null;
        PreparedStatement statement=null;
        ResultSet resultSet=null;
        try {
            connection= jdbctool.getconection();
            statement=connection.prepareStatement("delete\n" +
                    "from `servlet`.`question`\n" +
                    "where `questionId` = ?;");
            statement.setString(1,request.getParameter("quesid"));
            int i=statement.executeUpdate();
            if (i==1)
            {
                out.write("删除成功！");
            }
            else {
                out.write("删除失败！");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            jdbctool.close(connection,statement,resultSet);
        }
        System.out.println(request.getParameter("quesid"));
    }
}
